//
//  SchoolRootViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/10/23.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import XLPagerTabStrip

@objc protocol SchoolRootDelegate {
    @objc optional func changeScrollHeight(height:CGFloat) //改变滑动高度
    @objc optional func updateTitle() //刷新标题
}

class SchoolRootViewController: ButtonBarPagerTabStripViewController {
    
    weak var schoolDelegate : SchoolRootDelegate?
    
    fileprivate var schoolId = ""
    
    init(schoolId:String) {
        super.init(nibName: nil, bundle: nil)
        
        self.schoolId = schoolId
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        topBarStyle()
        super.viewDidLoad()
        
        
    }
    
    //AMRK: 顶部滚动条样式
    fileprivate func topBarStyle() {
        
        settings.style.buttonBarBackgroundColor = UIColor.mineColor()
        settings.style.buttonBarItemTitleColor = UIColor.black
        settings.style.buttonBarItemBackgroundColor = UIColor.clear
        settings.style.selectedBarBackgroundColor = UIColor.red
        settings.style.buttonBarItemFont = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        settings.style.selectedBarHeight = 3
        settings.style.buttonBarHeight = RATIO_H(maxNum: 40)
        
        //修改选中字体颜色
        changeCurrentIndexProgressive = {(oldCell,newCell,progressPercentage,changeCurrentIndex,animated) in
            
            oldCell?.label.textColor = UIColor.black
            newCell?.label.textColor = UIColor.red
        }
    }
    
    //MARK: 滑动的子控制
    override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
        
        let titleArray = [handlingManuals,questions,card]
        let urlArray = ["1","2","3"]
        
        var viewControllers = [UIViewController]()
        
        for i in 0..<titleArray.count {
            let schoolNewsVC = SchoolNewsViewController.init(schoolId: self.schoolId, type: urlArray[i])
            schoolNewsVC.itemInfo.title = titleArray[i]
            schoolNewsVC.delegate = self
            viewControllers.append(schoolNewsVC)
        }
        
        return viewControllers
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        

    }
    

}

extension SchoolRootViewController : SchoolNewsDelegate {
    
    //MARK: 改变坐标
    func changeScrollHeight(height: CGFloat) {
        
        self.schoolDelegate?.changeScrollHeight!(height: height)
    }
    
    //MARK: 刷新标题
    func updateTitle() {
        
        self.schoolDelegate?.updateTitle!()
    }
}
